package com.coexist.listnotes;

import java.io.IOException;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class ListnotesServlet extends HttpServlet {
   public void doGet(HttpServletRequest req, HttpServletResponse resp)
         throws IOException {
      String requestType = req.getParameter("requestType");
      if ("listNotes".equals(requestType)) {
         doListNotes(req, resp);
      }
   }

   private void doListNotes(HttpServletRequest req, HttpServletResponse resp)
         throws IOException {
      PersistenceManager pm = PMF.get().getPersistenceManager();
      Query query = pm.newQuery(Item.class);
      query.setFilter("parent == null");
      query.setOrdering("index");
      try {
         resp.getWriter().write("Notes: ");
      } finally {
         pm.close();
      }
   }
}
